package com.itheima.mapper;


import com.itheima.domain.Student;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface StudentMapper {
    //查询学生和选择课程（一个学生选择了多门课程）
    /*查询所有学生
    select * from student
    根据学生表id字段的值，去查询另外两个表
    select c.* from stu_cr sc,course c where sc.cid=c.id and sc.sid=1*/


@Select("select * from student")
    @Results({
            //封装学生基本信息
            @Result(column = "id",property = "id",id =true),
            @Result(column = "name",property = "name"),
            @Result(column = "age",property = "age"),
        //封装课程的集合信息
        @Result(
                property = "courses",
                javaType = List.class,
                column = "id",
                many = @Many(select = "com.itheima.mapper.CourseMapper.findBySid",fetchType = FetchType.LAZY)


        )
    })


    public List<Student>findAll();
}
